function code(n) {
    //小写字母
    var lower = [];
    for (var i = 97; i <= 122; i++) {
        lower.push(String.fromCharCode(i));
    }
    //大写字母
    var upper = [];
    for (var i = 65; i <= 90; i++) {
        upper.push(String.fromCharCode(i));
    }
    //数字
    var numArr = [];
    for (var i = 0; i <= 9; i++) {
        numArr.push(i + '')
    }
    //将数字，大写字母，小写字母放到一个新的数组
    var arr = [];
    arr = lower.concat(upper, numArr);
    n = n || 4;
    var res = '';
    for (i = 0; i < n; i++) {
        res += arr[rand(0, arr.length)];
    }

    //判断验证码的条件（包含大写字母，小写字母，数字）
    //不满足就调用code(n)
    //满足就return res

    var a = 0, b = 0, c = 0;
    for (var i in res) {
        if (numArr.includes(res[i])) {
            a = 1;
            continue;
        }
        if (lower.includes(res[i])) {
            b = 1;
            continue;
        }
        if (upper.includes(res[i])) {
            c = 1;
        }
    }
    if (a + b + c === 3) {
        return res;
    }
    return code(n);
}
//随机数
function rand(min, max) {
    return parseInt(Math.random() * (max - min) + min);
}